import { login, getUserProfile, getUserPropic } from '@/api/user'

import { getToken, removeToken, setToken } from '@/utils/auth.js'
const state = {
  token: getToken(),
  UserInfo: {}
}
const mutations = {
  // 设置token
  setToken(state, sum) {
    state.token = sum
  },
  // 获取个人基本信息
  setUserInfo(state, sum) {
    state.UserInfo = sum
  },
  // 点击退出删除vuex中的内容

  removeState(state) {
    removeToken()
    state.token = null
  }
}
const actions = {
  async login(context, data) {
    const a = await login(data)
    context.commit('setToken', a.data)
    setToken(a.data)
    return a
  },
  // 个人基本信息
  async getUserInfo(context) {
    const a = await getUserProfile()
    const b = await getUserPropic(a.data.userId)
    const cpic = { ...a.data, ...b.data }
    context.commit('setUserInfo', cpic)
  }
}
const getters = {

}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
